package cn.com.wangluotongxin.mall.rabbitmq;

import cn.com.wangluotongxin.mall.rabbitmq.listener.MallRabbitmqConstants;
import cn.com.wangluotongxin.mall.rabbitmq.pojo.ActivityInfoPojo;
import cn.com.wangluotongxin.mall.rabbitmq.pojo.GoodsInfoPojo;
import cn.com.wangluotongxin.mall.rabbitmq.pojo.QuickQueryPojo;
import cn.com.wangluotongxin.mall.service.IMallActivityInfoService;
import cn.com.wangluotongxin.mall.service.IMallGoodsInfoService;
import cn.com.wangluotongxin.mall.service.IMallQuickQueryService;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RabbitmqListener {

    @Autowired
    private IMallQuickQueryService quickQueryService;
    @Autowired
    private IMallActivityInfoService activityInfoService;
    @Autowired
    private IMallGoodsInfoService goodsInfoService;

    @RabbitListener(queues = MallRabbitmqConstants.MALL_QUICK_QUERY_SYNC, ackMode = "AUTO")
    public void quickQuerySync(QuickQueryPojo pojo) {
        log.info("收到快捷查询同步信息:{}", JSONObject.toJSONString(pojo));
        quickQueryService.quickQuerySync(pojo);
    }

    @RabbitListener(queues = MallRabbitmqConstants.MALL_ACTIVITY_INFO_SYNC, ackMode = "AUTO")
    public void activityInfoSync(ActivityInfoPojo pojo) {
        log.info("收到活动同步信息:{}", JSONObject.toJSONString(pojo));
        activityInfoService.activityInfoSync(pojo);
    }

    @RabbitListener(queues = MallRabbitmqConstants.MALL_GOODS_INFO_SYNC, ackMode = "AUTO")
    public void  goodsInfoSync(GoodsInfoPojo pojo) {
        log.info("收到商品同步信息:{}", JSONObject.toJSONString(pojo));
        goodsInfoService.goodsInfoSync(pojo);
    }
}
